package com.fractalwrench.harmonybootstrap.sample;

import static com.fractalwrench.harmonybootstrap.sample.ResourceTable.Layout_example_bootstrap_button;

import com.beardedhen.harmonybootstrap.BootstrapButton;
import com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapBrand;
import com.beardedhen.harmonybootstrap.api.defaults.DefaultBootstrapSize;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

public class BootstrapButtonExample extends AbilitySlice implements Component.ClickedListener {

    private DefaultBootstrapSize size = DefaultBootstrapSize.LG;
    BootstrapButton exampleCorners;
    BootstrapButton exampleOutline;
    BootstrapButton exampleSize;
    BootstrapButton exampleTheme;
    BootstrapButton exampleCustomStyle;
    BootstrapButton bbuttonexampleDisabledPrimary;
    BootstrapButton bbuttonexampleDisabledSuccess;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(getContext()).parse(Layout_example_bootstrap_button, null, false);
        exampleCorners = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_corners);
        exampleOutline = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_outline);
        exampleSize = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_size);
        exampleTheme = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_theme);
        exampleTheme = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_theme);
        exampleCustomStyle = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_example_bbutton_custom_style);
        bbuttonexampleDisabledPrimary = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_disabled_primary);
        bbuttonexampleDisabledSuccess = (BootstrapButton) rootLayout.findComponentById(ResourceTable.Id_bbutton_example_disabled_successs);

        exampleCorners.setClickedListener(this);
        exampleOutline.setClickedListener(this);
        exampleSize.setClickedListener(this);
        exampleTheme.setClickedListener(this);
        exampleCustomStyle.setClickedListener(this);

        bbuttonexampleDisabledPrimary.setClickedListener(this);
        bbuttonexampleDisabledPrimary.setEnabled(false);

        bbuttonexampleDisabledSuccess.setClickedListener(this);
        bbuttonexampleDisabledSuccess.setEnabled(false);

        setupCustomStyle();
        super.setUIContent(rootLayout);
    }

    private void setupCustomStyle() {
        exampleCustomStyle.setBootstrapSize(3.0f);
        exampleCustomStyle.setBootstrapBrand(new CustomBootstrapStyle(this));
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_bbutton_example_corners:
                exampleCorners.setRounded(!exampleCorners.isRounded());
                break;
            case ResourceTable.Id_bbutton_example_outline:
                exampleOutline.setShowOutline(!exampleOutline.isShowOutline());
                break;
            case ResourceTable.Id_bbutton_example_size:
                switch (size) {
                    case XS:
                        size = DefaultBootstrapSize.SM;
                        break;
                    case SM:
                        size = DefaultBootstrapSize.MD;
                        break;
                    case MD:
                        size = DefaultBootstrapSize.LG;
                        break;
                    case LG:
                        size = DefaultBootstrapSize.XL;
                        break;
                    case XL:
                        size = DefaultBootstrapSize.XS;
                        break;
                }
                exampleSize.setBootstrapSize(size);
                break;
            case ResourceTable.Id_bbutton_example_theme:
                switch ((DefaultBootstrapBrand) exampleTheme.getBootstrapBrand()) {
                    case PRIMARY:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.SUCCESS);
                        break;
                    case SUCCESS:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.WARNING);
                        break;
                    case WARNING:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.DANGER);
                        break;
                    case DANGER:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.INFO);
                        break;
                    case INFO:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.SECONDARY);
                        break;
                    case SECONDARY:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.REGULAR);
                        break;
                    case REGULAR:
                        exampleTheme.setBootstrapBrand(DefaultBootstrapBrand.PRIMARY);
                        break;
                }
        }
    }
}
